package com.hzit.proxy.base;

import com.alibaba.fastjson.JSONObject;
import com.hzit.net.util.RedisUtil;
import com.hzit.net.util.WXNetUtil;

public class ImageQRCode {


    public static String getImageUrl(){
        String redisKey="weixin:qrImage";
        String image= RedisUtil.get(redisKey);
        if(image==null) {
            String token = AccessToken.getToken();
            String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token;
            String param = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"bj2004_test01\"}}}";
            String result = WXNetUtil.post(url, param);
            JSONObject jsonObject = JSONObject.parseObject(result);
            if (jsonObject.containsKey("ticket")) {
                String ticket = jsonObject.getString("ticket");
                String imageUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + ticket;

                return imageUrl;
            }
        }
        return image;
    }
}
